<?php
require_once("src/config.php");

if (isset($_POST["langue"])) $strLangue = $_POST["langue"];
if (isset($_GET["langue"])) $strLangue = $_GET["langue"];

if($strLangue =='en'){
    require_once('src/english.php');
}else{
    require_once('src/french.php');
}

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
session_start();
$queryParam = '';
$imgName='';

if(!isset($_REQUEST['t'])){
    echo "<script type='text/javascript'>\n top.location.href='".FACEBOOK_CANVAS_URL."';\n</script>";   
}else if($_REQUEST['t']=='drawing'){
    if(empty($_COOKIE['login'])){
        #setcookie for login
       setcookie("login","1",0);
    
        $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
                . APP_ID . "&redirect_uri=" . urlencode(FACEBOOK_CANVAS_URL)."&scope=publish_stream,email";
        echo("<script type='text/javascript'> top.location.href='" . $auth_url . "';</script>");
        exit;    
    }else{    
        #setcookie for login
        setcookie("login","",0);
        require_once("src/facebookinclude.php");        
    }
    include("drawing.php");    
}else if($_REQUEST['t']=='gallery'){
    //setcookie("login","",0); 
    include("gallery.php");
}else if ($_REQUEST['t']=='image'){
    if(!empty($_REQUEST['id'])){
        $queryParam = '?t=image&id='.$_REQUEST['id'];
        
        require_once ('src/lib.php');
        if(!tep_db_checkDb())
        	 { die('Cannot connect to DB. Error: '.mysql_error());}
        	#handle query string to get data
        	$queryString = 'select * from images where id='.$_REQUEST['id'];
         	$query = mysql_query($queryString);
         	if($query == null) die('Query to database is errored');
          	$row = mysql_fetch_array($query);
             $imageName = $row['imagename'];  
             $imgName=str_replace(".png","thumb.png",$imageName);
    }
    include("image.php");
}


?>

<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <base target="_top"/>
    <title>Scribble Image Gallery</title>
    <meta property="og:title" content="Tintamar flag game" />
    <meta property="og:type" content="article" />
    <meta property="og:url" content="<?php echo FACEBOOK_IMAGE_URL."&id=".$_REQUEST['id'];?>" />
    <meta property="og:image" content="<?php echo "http://www.intelligentdailyblog.fr/vn/drawImage/thumbnails/".$imgName;?>" />
    <meta property="og:site_name" content="intelligentdailyblog" />
    <meta property="fb:admins" content="100000257847983" />
    <meta property="fb:app_id" content="<?php echo APP_ID ?>"/>
    <meta property="og:description" content="Dessinez le drapeau de Tintama"/>
    
</head>